Repository navigation
fix(storage): close worker loop async clients - #4740
be-student wants to merge 2 commits into
Conversation
Review: fix(storage): close worker loop async clientsReviewed against the #4726 analysis — this addresses the worker-loop leg of that failure mode cleanly, and the classmethod shape makes it reusable for other loop owners. What checks out
Scope note (complementary, not blocking) #4726 traced two more reference legs that this PR intentionally doesn't touch: Tests: the worker-loop integration test (events ordering: close before loop close) and the classmethod unit tests cover the new path; LGTM. |
|
Verified this end-to-end on top of the PR head (7ff4474) — the mechanism is sound and the tests have real discriminative power. Detailed evidence below. 1. The core mechanism, confirmed against
|
Description
Queue workers previously closed their private event loop while
LoopScopedAsyncClientCacheinstances still retained clients created on that loop. Later garbage collection could attempt to close an OpenAI/httpx transport against the dead loop and raiseRuntimeError: Event loop is closedin unrelated work.This change registers loop-scoped caches weakly and closes only the clients owned by the current worker loop before
loop.close(). Clients belonging to other active loops remain available.Human Involvement
Related Issue
Fixes #4726
Type of Change
Changes Made
LoopScopedAsyncClientCacheinstances with weak references.aclose()and falls back toclose().Testing
Commands:
Result: 6 focused tests passed; Ruff and mypy passed. The first
uv run pytestattempt could not build the editable package because Cargo was unavailable locally, so the focused checks used the existing project virtual environment with the worktree onPYTHONPATH.Checklist
Screenshots (if applicable)
Not applicable.
Additional Notes
The change affects only internal client lifecycle behavior. It does not alter public APIs, configuration, or persisted data.